{extend name="/index/base" /}

{block name="content"}
<div class="layui-card">
    <div class="layui-card-header layuiadmin-card-header-auto">
        <h2>修改分类</h2>
    </div>
    <div class="layui-card-body">
        <form class="layui-form" action="" method="post">
            <div class="layui-form-item">
                <label for="" class="layui-form-label">父级</label>
                <div class="layui-input-block">
                    <select name="parent_id" id="parent_id" lay-search>
                        <option value="0"  {if 0 eq $data['parent_id']}select="selected"{/if}>顶级分类</option>
                        {foreach $parents as $k => $v}
                        <option value="{$v['id']}" {if $v['id'] eq $data['parent_id']}selected{/if}>{$v['name']}</option>
                        {foreach $v['sub'] as $k1 => $v1}
                        <option value="{$v1['id']}" {if $v1['id'] eq $data['parent_id']}selected{/if}>______{$v1['name']}</option>
                        {/foreach}
                        {/foreach}
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="" class="layui-form-label">分类名称{$data['parent_id']}</label>
                <div class="layui-input-block">
                    <input type="text" name="name" value="{$data['name']??''}" lay-verify="required" class="layui-input name" placeholder="">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="" class="layui-form-label">排序</label>
                <div class="layui-input-block">
                    <input class="layui-input sort" type="text" name="sort" value="{$data['sort']??''}" placeholder="如：1" >
                </div>
            </div>

            <div class="layui-form-item">
                <label for="" class="layui-form-label">展示的URL</label>
                <div class="layui-input-block">
                    <input class="layui-input url" type="text" name="url" value="{$data['url']??''}" placeholder="" >
                </div>
            </div>

            <div class="layui-form-item">
                <label for="" class="layui-form-label">seo_title</label>
                <div class="layui-input-block">
                    <input class="layui-input seo_title" type="text" name="seo_title" value="{$data['seo_title']??''}" placeholder="" >
                </div>
            </div>
            <div class="layui-form-item">
                <label for="" class="layui-form-label">seo关键字</label>
                <div class="layui-input-block">
                    <input class="layui-input seo_keywords" type="text" name="seo_keywords" value="{$data['seo_keywords']??''}" placeholder="" >
                </div>
            </div>

            <div class="layui-form-item">
                <label for="" class="layui-form-label">seo描述</label>
                <div class="layui-input-block">
                    <textarea name="seo_description" placeholder="" class="layui-textarea seo_description">{$data['seo_description']??''}</textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="hidden" class="id" value="{$data['id']}" />
                    <span type="submit" id="submit" class="layui-btn" lay-submit="" lay-filter="formDemo">确 认</span>
                    <a  class="layui-btn" href="{:URL('admin/category/index')}" >返 回</a>
                </div>
            </div>
        </form>
    </div>
</div>

{/block}


{block name="script"}
<script>
    layui.use(['layer','table','form'],function () {
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.$ //由于layer弹层依赖jQuery，所以可以直接得到

        //搜索
        form.on('submit(formDemo)', function(data2) {
            var name = $(".name").val()
            var sort = $(".sort").val();
            var parent_id = $("#parent_id").val();
            var id = $(".id").val();

            if(sort>124){
                layer.msg('排序不能超过124');
                return false;
            }
            var seo_title = $(".seo_title").val();
            var seo_keywords = $(".seo_keywords").val();
            var seo_description = $(".seo_description").val();
            var url = $(".url").val();

            var data = {'name':name,'sort':sort,'parent_id':parent_id,'id':id,'seo_description':seo_description,'seo_keywords':seo_keywords,'seo_title':seo_title,"url":url};

            $.ajax({
                type: 'POST',
                url: '{:url("admin/category/update")}',
                data: data,
                success: function (ret) {
                    if (ret.code == 200) {
                        layer.msg(ret.msg, {icon: 6, time: 1000}, function () {
                            window.location.href='{:url("admin/category/index")}';
                        });
                    } else {
                        layer.msg(ret.msg);
                    }
                    return false;
                }
            });
        })

    })
</script>
{/block}
